package org.datedemo;

import org.webrx.D;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Calendar;
import java.util.Date;

public class Calendar2 {
    public static void main(String[] args) {
        //判断闰年
        var c2 = Calendar.getInstance();
        int cy = c2.get(Calendar.YEAR);
        for (int year = 1000; year <= cy; year++) {
            if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0) {
                System.out.printf("%d年是闰年%n", year);
            }
        }

        Date ddd = new Date();


        //java 8.0 新增
        LocalDate now = LocalDate.of(2000,1,1);
        System.out.println(now.isLeapYear());
        System.out.printf("%tF %<tA%n",now);

        //LocalTime

        //LocalDateTime java.util.Date java.util.Calendar

        var c1 = Calendar.getInstance();
        int year = 2024;
        int month = 2;
        c1.set(year, month, 0);
        int days = c1.get(Calendar.DAY_OF_MONTH);
        //System.out.printf("%tF %<tT %n", c1);
        //System.out.println(c1.get(Calendar.DAY_OF_MONTH));
        System.out.printf("%d年%d月有%d天%n", year, month, days);


        var c = Calendar.getInstance();
        System.out.printf("%tF %<tT %n", c);

        c.set(Calendar.MONTH, c.get(Calendar.MONTH));
        c.set(Calendar.DATE, 1);
        System.out.printf("%tF %<tT %n", c);

        c.set(Calendar.MONTH, c.get(Calendar.MONTH) + 1);
        c.set(Calendar.DATE, 0);
        System.out.printf("%tF %<tT %n", c);


    }
}
